namespace QMVnSoft.Lists
{
    using QMVnSoft;
    using QMVnSoft.Controls;
    using QMVnSoft.DAL;
    using System;
    using System.ComponentModel;
    using System.Data;
    using System.Drawing;
    using System.Windows.Forms;

    public class FormDmKhoEditor : FormListEditor
    {
        private IContainer components;
        private LabelControl lblMa_Kho;
        private LabelControl lblTen_Kho;
        private LabelControl lblTen_Kho_E;
        private TextControl txtMa_Kho;
        private TextControl txtTen_Kho;
        private TextControl txtTen_Kho_E;

        public FormDmKhoEditor()
        {
            this.InitializeComponent();
        }

        protected override void Dispose(bool disposing)
        {
            if (disposing && (this.components != null))
            {
                this.components.Dispose();
            }
            base.Dispose(disposing);
        }

        private void InitializeComponent()
        {
            //ComponentResourceManager manager = new ComponentResourceManager(typeof(FormDmKhoEditor));
            this.txtMa_Kho = new TextControl();
            this.lblMa_Kho = new LabelControl();
            this.txtTen_Kho = new TextControl();
            this.lblTen_Kho = new LabelControl();
            this.txtTen_Kho_E = new TextControl();
            this.lblTen_Kho_E = new LabelControl();
            base.SuspendLayout();
            base.txtMa_Loai3.FirstFilter = "Type = 'KH3'";
            base.txtMa_Loai3.Location = new Point(0x18c, 0x5e);
            base.txtMa_Loai3.Size = new Size(0x85, 20);
            base.txtMa_Loai3.TabIndex = 5;
            base.txtMa_Loai2.FirstFilter = "Type = 'KH2'";
            base.txtMa_Loai2.Location = new Point(0x103, 0x5e);
            base.txtMa_Loai2.Size = new Size(0x86, 20);
            base.txtMa_Loai2.TabIndex = 4;
            base.txtMa_Loai1.FirstFilter = "Type = 'KH1'";
            base.txtMa_Loai1.Location = new Point(0x7b, 0x5e);
            base.txtMa_Loai1.Size = new Size(0x85, 20);
            base.txtMa_Loai1.TabIndex = 3;
            base.lblPhan_Loai.Location = new Point(12, 0x61);
            this.txtMa_Kho.CharacterCasing = CharacterCasing.Upper;
            this.txtMa_Kho.CheckTextSearched = false;
            this.txtMa_Kho.DisabledForeColor = Color.Empty;
            this.txtMa_Kho.Font = new Font("Arial", 8.25f);
            this.txtMa_Kho.Location = new Point(0x7b, 0x1c);
            this.txtMa_Kho.MaxLength = 0x20;
            this.txtMa_Kho.Name = "txtMa_Kho";
            this.txtMa_Kho.OldValue = null;
            this.txtMa_Kho.Size = new Size(0x85, 20);
            this.txtMa_Kho.TabIndex = 0;
            this.txtMa_Kho.UserTextLength = AppInstance.TextControlLength.ItemCode;
            this.txtMa_Kho.UserTrimMode = AppInstance.TextControlTrimMode.All;
//            this.txtMa_Kho.Value = null;//manager.GetObject("txtMa_Kho.Value");
            this.lblMa_Kho.AutoSize = true;
            this.lblMa_Kho.Font = new Font("Arial", 8.25f);
            this.lblMa_Kho.Location = new Point(12, 0x1f);
            this.lblMa_Kho.Name = "lblMa_Kho";
            this.lblMa_Kho.Size = new Size(0x29, 14);
            this.lblMa_Kho.TabIndex = 4;
            this.lblMa_Kho.Text = "Mã kho";
            this.txtTen_Kho.Anchor = AnchorStyles.Right | AnchorStyles.Left | AnchorStyles.Top;
            this.txtTen_Kho.CheckTextSearched = false;
            this.txtTen_Kho.DisabledForeColor = Color.Empty;
            this.txtTen_Kho.Font = new Font("Arial", 8.25f);
            this.txtTen_Kho.Location = new Point(0x7b, 50);
            this.txtTen_Kho.MaxLength = 128;
            this.txtTen_Kho.Name = "txtTen_Kho";
            this.txtTen_Kho.OldValue = null;
            this.txtTen_Kho.Size = new Size(0x196, 20);
            this.txtTen_Kho.TabIndex = 1;
            this.txtTen_Kho.UserTextLength = AppInstance.TextControlLength.ItemDescription;
            this.txtTen_Kho.UserTrimMode = AppInstance.TextControlTrimMode.All;
//            this.txtTen_Kho.Value = null;//manager.GetObject("txtTen_Kho.Value");
            this.lblTen_Kho.AutoSize = true;
            this.lblTen_Kho.Font = new Font("Arial", 8.25f);
            this.lblTen_Kho.Location = new Point(12, 0x35);
            this.lblTen_Kho.Name = "lblTen_Kho";
            this.lblTen_Kho.Size = new Size(0x2d, 14);
            this.lblTen_Kho.TabIndex = 4;
            this.lblTen_Kho.Text = "Tên kho";
            this.txtTen_Kho_E.Anchor = AnchorStyles.Right | AnchorStyles.Left | AnchorStyles.Top;
            this.txtTen_Kho_E.CheckTextSearched = false;
            this.txtTen_Kho_E.DisabledForeColor = Color.Empty;
            this.txtTen_Kho_E.Font = new Font("Arial", 8.25f);
            this.txtTen_Kho_E.Location = new Point(0x7b, 0x48);
            this.txtTen_Kho_E.MaxLength = 128;
            this.txtTen_Kho_E.Name = "txtTen_Kho_E";
            this.txtTen_Kho_E.OldValue = null;
            this.txtTen_Kho_E.Size = new Size(0x196, 20);
            this.txtTen_Kho_E.TabIndex = 2;
            this.txtTen_Kho_E.UserTextLength = AppInstance.TextControlLength.ItemDescription;
            this.txtTen_Kho_E.UserTrimMode = AppInstance.TextControlTrimMode.All;
//            this.txtTen_Kho_E.Value = null;//manager.GetObject("txtTen_Kho_E.Value");
            this.lblTen_Kho_E.AutoSize = true;
            this.lblTen_Kho_E.Font = new Font("Arial", 8.25f);
            this.lblTen_Kho_E.Location = new Point(12, 0x4b);
            this.lblTen_Kho_E.Name = "lblTen_Kho_E";
            this.lblTen_Kho_E.Size = new Size(0x4a, 14);
            this.lblTen_Kho_E.TabIndex = 4;
            this.lblTen_Kho_E.Text = "Tên tiếng Anh";
            base.AddTitleText = "Thêm mới kho hàng";
            base.AutoScaleDimensions = new SizeF(6f, 13f);
            base.ClientSize = new Size(0x222, 128);
            base.Controls.Add(this.lblTen_Kho_E);
            base.Controls.Add(this.lblTen_Kho);
            base.Controls.Add(this.lblMa_Kho);
            base.Controls.Add(this.txtTen_Kho_E);
            base.Controls.Add(this.txtTen_Kho);
            base.Controls.Add(this.txtMa_Kho);
            base.EditTitleText = "Sửa kho hàng";
            base.FirstFreeCode = "KH1";
            base.Name = "FormDmKhoEditor";
            base.SecondFreeCode = "KH2";
            this.Text = "Thêm mới kho hàng";
            base.ThirdFreeCode = "KH3";
            base.Controls.SetChildIndex(base.lblPhan_Loai, 0);
            base.Controls.SetChildIndex(base.txtMa_Loai1, 0);
            base.Controls.SetChildIndex(base.txtMa_Loai2, 0);
            base.Controls.SetChildIndex(base.txtMa_Loai3, 0);
            base.Controls.SetChildIndex(this.txtMa_Kho, 0);
            base.Controls.SetChildIndex(this.txtTen_Kho, 0);
            base.Controls.SetChildIndex(this.txtTen_Kho_E, 0);
            base.Controls.SetChildIndex(this.lblMa_Kho, 0);
            base.Controls.SetChildIndex(this.lblTen_Kho, 0);
            base.Controls.SetChildIndex(this.lblTen_Kho_E, 0);
            base.ResumeLayout(false);
            base.PerformLayout();
        }

        public override bool OnSave()
        {
            DataRow localCurrentRow;
            if (string.IsNullOrEmpty(this.txtMa_Kho.Text))
            {
                MessageBox.Show("Chưa nhập mã kho hàng!", AppInstance.SoftwareName, MessageBoxButtons.OK, MessageBoxIcon.Hand);
                return false;
            }
            if (string.IsNullOrEmpty(this.txtTen_Kho.Text))
            {
                MessageBox.Show("Chưa nhập tên kho hàng!", AppInstance.SoftwareName, MessageBoxButtons.OK, MessageBoxIcon.Hand);
                return false;
            }
            if (base.NewChecked)
            {
                localCurrentRow = base.LocalTable.NewRow();
            }
            else
            {
                localCurrentRow = base.LocalCurrentRow;
            }
            localCurrentRow["Ma_Kho"] = this.txtMa_Kho.Value;
            localCurrentRow["Ten_Kho"] = this.txtTen_Kho.Value;
            localCurrentRow["Ten_Kho_E"] = this.txtTen_Kho_E.Value;
            localCurrentRow["Ma_Loai1"] = base.txtMa_Loai1.Value;
            localCurrentRow["Ma_Loai2"] = base.txtMa_Loai2.Value;
            localCurrentRow["Ma_Loai2"] = base.txtMa_Loai2.Value;
            DmKhoDataAccess access = new DmKhoDataAccess();
            if (base.ShowMessage(localCurrentRow, access.SaveRow(base.NewChecked, localCurrentRow)))
            {
                return false;
            }
            if (base.NewChecked)
            {
                base.LocalTable.Rows.Add(localCurrentRow);
            }
            base.LocalCurrentRow = localCurrentRow;
            base.LocalTable.AcceptChanges();
            this.txtMa_Kho.Focus();
            return base.OnSave();
        }

        public override void OnShow()
        {
            this.txtMa_Kho.Value = base.LocalCurrentRow["Ma_Kho"];
            this.txtTen_Kho.Value = base.LocalCurrentRow["Ten_Kho"];
            this.txtTen_Kho_E.Value = base.LocalCurrentRow["Ten_Kho_E"];
            base.txtMa_Loai1.Value = base.LocalCurrentRow["Ma_Loai1"];
            base.txtMa_Loai2.Value = base.LocalCurrentRow["Ma_Loai2"];
            base.txtMa_Loai2.Value = base.LocalCurrentRow["Ma_Loai2"];
            base.OnShow();
        }
    }
}

